package com.yunwushanhe.controller;

import com.yunwushanhe.bean.ret.ResponseResult;
import com.yunwushanhe.service.FileUploadService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @Author 抬头看看天
 * @Date 2023-08-22  22:25:55
 */
@RestController
public class FileUploadController {

    @Resource
    private FileUploadService fileUploadService;

    @PostMapping("/upload")
    public ResponseResult<String> uploadImag(@RequestParam("img") MultipartFile img){
        try {
            return fileUploadService.uploadImag(img);
        } catch (Exception exception) {
            exception.printStackTrace();
            throw new RuntimeException("文件上传失败！");
        }
    }
}
